import { getComplianceDetail, getOtherViolation, getISPunishData, getISPunishFiveData } from '@/services/warning';

export default {
  namespace: 'creditrisk',

  state: {
    ComplianceData: {},
    OViolationData: {},
    ISPunishData: {},
    ISPunishFiveData: {}
  },

  effects: {
    *getComplianceData({ payload }, { call, put }) {
      try {
        const response = yield call(getComplianceDetail, payload);
        // console.log('<<< getComplianceData >>>', response);
        yield put({
          type: 'setDataType',
          payload: {
            ComplianceData: response
          },
        });
      } catch (e) {
        console.log('Error:', e);
      }
    },
    *getOViolationData({ payload }, { call, put }) {
      const response = yield call(getOtherViolation, payload);
      yield put({
        type: 'setDataType',
        payload: {
          OViolationData: response
        },
      });
    },
    *getISPunishData({ payload }, { call, put }) {
      try {
        const response = yield call(getISPunishData, payload);
        // console.log('<<< getComplianceData >>>', response);
        yield put({
          type: 'setDataType',
          payload: {
            ISPunishData: response
          },
        });
      } catch (e) {
        console.log('Error:', e);
      }
    },
    *getISPunishFiveData({ payload }, { call, put }) {
      try {
        const response = yield call(getISPunishFiveData, payload);
        // console.log('<<< getComplianceData >>>', response);
        yield put({
          type: 'setDataType',
          payload: {
            ISPunishFiveData: response
          },
        });
      } catch (e) {
        console.log('Error:', e);
      }
    },
  },
  reducers: {
    setDataType(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    }
  },
};
